package com.yidu.view;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>@Description: No Description</p>
 * <p>@Author yidu-liandyao</p>
 * <p>@Date: 2021-01-05</p>
 * <p>@Time: 13:54</p>
 */
public class SqlSessionTools {

    /**
     * 得到一个连接
     * @return
     */
    public static SqlSession getSession(){
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        //连接工厂
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is) ;
        //从工厂里面取出一个活的连接
        SqlSession session = sessionFactory.openSession() ;

        return session ;
    }
}
